<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>state</title>
  </head>
  <body>
    <div id="test"></div>
    <script
      src="https://unpkg.com/react@16/umd/react.production.min.js"
      crossorigin
    ></script>
    <script
      src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"
      crossorigin
    ></script>

    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>

    <script type="text/babel">
      class Weatch extends React.Component {
        //取消 构造器
        state = {
          isHot: false,
        };

        render() {
          return (
            <h2 onClick={this.h2Click}>
              点击发生变化{this.state.isHot ? "变化1" : "变化2"}
            </h2>
          );
        }
        //自定义方法 使用箭头函数 (箭头函数没有this指向特点)
        h2Click = () => {
          const isHot = this.state.isHot;
          console.log("点击事件");
          console.log(this);

          this.setState({ isHot: !isHot });
        };
      }

      ReactDOM.render(<Weatch />, document.getElementById("test"));
    </script>
  </body>
</html>
